_zimfw_run_tool() {
  local -r ztool=${1} zaction=${2} zmodule=${3} zdir=${4} zurl=${5}
  if [[ -z ${zurl} ]]; then
    if (( _zprintlevel > 1 )) print -u2 -PR <%= clear_line %>"<%= okay %>%B${zmodule}:%b Skipping external module"
    return 0
  fi
  local -ri zfrozen=${9}
  if (( zfrozen )); then
    if (( _zprintlevel > 1 )) print -u2 -PR <%= clear_line %>"<%= okay %>%B${zmodule}:%b Skipping frozen module"
    return 0
  fi
  case ${zaction} in
    install)
      if [[ -e ${zdir} ]]; then
        # Already installed
        return 0
      fi
      _zimfw_print -nR <%= clear_line %>"Installing ${zmodule}<%= ellipsis %>"
      ;;
    update)
      if [[ ! -d ${zdir} ]]; then
        print -u2 -PR <%= clear_line %>"%F{red}<%= error %>%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f"
        return 1
      fi
      _zimfw_print -nR <%= clear_line %>"Updating ${zmodule}<%= ellipsis %>"
      ;;
    *)
      print -u2 -PR <%= clear_line %>"%F{red}<%= error %>%B${zmodule}:%b Unknown action ${zaction}%f"
      return 1
      ;;
  esac
  local zcmd
  case ${ztool} in
<%= render_tools("src/tools/*", "zcmd") %>
    *)
      print -u2 -PR "<%= clear_line %>%F{red}<%= error %>%B${zmodule}:%b Unknown tool ${ztool}%f"
      return 1
      ;;
  esac
  zsh -c ${zcmd} ${ztool} ${_zprintlevel} "${@[2,8]}"
}
